package com.xiaowen.login;

import com.xiaowen.login.dto.LoginReqDTO;
import com.xiaowen.redis.RedisKeys;
import com.xiaowen.redis.RedisUtils;
import com.xiaowen.tool.SmsUtil;
import com.xiaowen.tool.dto.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

/**
 * 登录相关
 * User: yf-wenhao
 * Date: 2024/9/18
 * Time: 下午1:51
 */
@RestController
@RequestMapping(value = "/login")
@Slf4j
public class LoginController {

    @Autowired
    private RedisUtils redisUtils;


    //发送验证码
    @GetMapping(value = "/authCode")
    public Result<Boolean> sendAuthCode(@RequestParam String phoneNumber) {
        Random random = new Random();
        int code = random.nextInt(999999) + 100000; // 生成一个六位数的随机数
        String codeValue = String.valueOf(code);
        //通过redis生成随机的code
        redisUtils.set(phoneNumber + "_" + RedisKeys.SMS_REDIS_KEY, codeValue, 5 * 60);
        SmsUtil.send(phoneNumber, codeValue);
        //发送code
        return new Result<Boolean>().ok(true);
    }


    //登录接口
    @GetMapping
    public Result login(LoginReqDTO loginReqDTO) {
        return new Result();
    }




}
